package main;

import java.rmi.RemoteException;
import java.util.ArrayList;

import gate.IGateEx;
import client.remote.ClientReceiver;

public class GateTaskFactory
{
	private static IGateEx gate;
	public static void setUpFactory(IGateEx rgate)
	{
		gate = rgate;
	}
	public static Runnable createXXTask()
	{
		return null;
	}

	public static Runnable createRegisterTask(final long userId, final ClientReceiver clientReceiver)
	{
		return new Runnable()
		{
			
			@Override
			public void run()
			{
				try
				{
					gate.clientEntered(userId, clientReceiver);
				} catch (RemoteException e)
				{
					e.printStackTrace();
				}
			}
		};
	}
	public static Runnable createUnregisterTask(final long clientId)
	{
		return new Runnable()
		{
			
			@Override
			public void run()
			{
				try
				{
					gate.clientLeft(clientId);
				} catch (RemoteException e)
				{
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		};
	}
	public static Runnable createNewRoomTask(final ArrayList<Long> clients,
			final int roomId)
	{
		return new Runnable()
		{
			
			@Override
			public void run()
			{
				try
				{
					gate.newGameStarted(clients, roomId);
				} catch (RemoteException e)
				{
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		};
	}
	public static Runnable createClientDisconnectRoomTask(final int roomId,final long clientId)
	{
		return new Runnable()
		{
			
			@Override
			public void run()
			{
				try
				{
					gate.clientLeftGame(roomId,clientId);
				} catch (RemoteException e)
				{
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		};
	}
}
